#include "Singleton.h"
#include "FiniteStateMachine.h"
#include "GameEngine.h"
#include "image/QImageFactory.h"

Singleton::MapType * Singleton::_registryMap = new std::map<std::string, Singleton *>();

Singleton::Singleton(void)
{
}

Singleton::~Singleton(void)
{
}

Singleton * Singleton::getInstance(std::string const * className){
	MapType::iterator it = _registryMap->find(*className);
        if( it == _registryMap->end() )
                return 0;
	return (*_registryMap)[*className];
}

void Singleton::release(std::string & className){
        MapType::iterator it = _registryMap->find(className);
	if(it != _registryMap->end())
		delete (*it).second;
	_registryMap->erase(className);
}

std::string * Singleton::getClassName(){
        return new std::string("Singleton");
}

void Singleton::registerAll(){
    registerClass(new FiniteStateMachine());
    registerClass(new GameEngine());
    registerClass(new QImageFactory());
}
